/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife updater.

    Ages of Strife updater is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife updater is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife updater.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Trade {
	public double coal_gold;
	public double iron_gold;
	//public double iron_coal;
	
	//public int gold_total;
	public int iron_total;
	public int coal_total;
	
	public Trade( /*int gold_total,*/ int iron_total, int coal_total, double coal_gold, double iron_gold/*, double iron_coal*/ ) {
		//this.gold_total = gold_total;
		this.iron_total = iron_total;
		this.coal_total = coal_total;
		this.coal_gold = coal_gold;
		this.iron_gold = iron_gold;
		//this.iron_coal = iron_coal;
	}

	public void add( int iron_total, int coal_total, double coal_gold, double iron_gold ) {
		if( coal_total != 0 ) {
			this.coal_gold = ( this.coal_gold * this.coal_total + coal_gold * coal_total ) / ( this.coal_total + coal_total );
		}
		if( iron_total != 0 ) {
			this.iron_gold = ( this.iron_gold * this.iron_total + iron_gold * iron_total ) / ( this.iron_total + iron_total );
		}
//		if( ( this.coal_total + this.iron_total + coal_total + iron_total ) != 0 ) {
//			this.iron_coal = ( this.iron_coal * ( this.coal_total + this.iron_total ) + ( iron_coal * ( coal_total + iron_total ) ) ) / ( this.coal_total + this.iron_total + coal_total + iron_total );
//		}
//		this.gold_total += gold_total;
		this.iron_total += iron_total;
		this.coal_total += coal_total;
	}
}
